package light.head.dao.oa;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import light.head.constant.Parm;
import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.framework.entity.PageBean;
import light.head.model.Record;

import org.springframework.stereotype.Service;


@Service
public class RecordDAO extends BaseDAO<Record, Integer>{
	
	public RESULT findByMap(Map<String, String> map, PageBean pageBean) {
		StringBuffer hql = new StringBuffer("FROM Record r WHERE 1 = 1");
		
		List<Object> list = null;
		if (map != null) {
			list = new ArrayList<Object>();
			String vc = map.get(Parm.VC);
			String vu = map.get(Parm.VU);
			String oc = map.get(Parm.OC);
			if(null != vc && !"".equals(vc)) {
				hql.append(" AND r.vc LIKE ?");
				list.add("%" + vc + "%");
			}if(null != vu && !"".equals(vu)) {
				hql.append(" AND r.vu LIKE ?");
				list.add("%" + vu + "%");
			}if(isNotNull(oc)) {
				hql.append(" AND r.oc = ?");
				list.add(Integer.parseInt(oc));
			}
		}
		
		hql.append(" ORDER BY r.code DESC");
		
		if (findToPageBean(hql.toString(), pageBean, list) == RESULT.SUCCESS)
			return RESULT.SUCCESS;
		return RESULT.ERROR;
	}
	 

}
